import osg2

max_depth = 3
width = 2

osg2.osgInit([])

scene_root = osg2.Node.create()
scene_root.setCore(osg2.Group.create())
osg2.setName(scene_root, "R")

def genTree(root, depth):
   if depth >= max_depth:
      return
      
   for x in range(width):
      new_node = osg2.Node.create()
      root.addChild(new_node)
      
      new_node.setCore(osg2.Group.create())
      osg2.setName(new_node, "%s.%s"%(osg2.getName(root),x))
      genTree(new_node, depth+1)

genTree(scene_root, 0)

pt = osg2.helpers.PrintTreeTraverser()
pt.traverse(scene_root)

osg2.SceneFileHandler.the().write(scene_root, "test_scene_gen.osb")
